package com.huawei.appgallery.search.ui.card;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ToggleButton;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.MultiLineLabelLayout;
import com.huawei.appgallery.search.ui.bean.HotWordInfo;
import com.huawei.appgallery.search.ui.cardbean.HotWordCardBean;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import o.cdh;
import o.cfw;
import o.cgz;
import o.chy;
import o.cuv.a;
import o.cuv.b;
import o.cuv.e;
import o.cuv.f;
import o.cux;
import o.cvo;
import o.dge.d;
import o.dgh;
import o.dgu;
import o.ContentManager;
import o.dyf;
import o.dyk;
import o.CollectCheck;
import o.evx;

public class HotWordBaseCard extends BaseDistCard {
    protected int ʻ;
    private LayoutInflater ʼ;
    protected Map<Object, String> ʽ;
    protected MultiLineLabelLayout ˋ;
    private String ˋॱ;
    private chy ˏॱ;
    protected List<HotWordInfo> ॱॱ = null;
    private List<HotWordInfo> ᐝ = null;

    public HotWordBaseCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        this.ʼ = (LayoutInflater) view.getContext().getSystemService("layout_inflater");
        this.ˋ = (MultiLineLabelLayout) view.findViewById(b.ꞌ);
        this.ʽ = new HashMap();
        ʽ(view);
        this.ʻ = cdh.ˎ((Activity) this.ˋ.getContext());
        return this;
    }

    public void ˏ(CardBean cardBean) {
        if (ˉ() != null) {
            super.ˏ(cardBean);
            HotWordCardBean hotWordCardBean = (HotWordCardBean) cardBean;
            this.ᐝ = hotWordCardBean.ˊ();
            this.ˋॱ = hotWordCardBean.ꓸ();
            if (CollectCheck.isEmpty(this.ᐝ) || hotWordCardBean.ㆍ() <= 0) {
                ˎ();
            } else {
                ॱ(hotWordCardBean);
            }
        }
    }

    protected void ॱ(HotWordCardBean hotWordCardBean) {
        ˉ().setVisibility(0);
        LayoutParams layoutParams = (LayoutParams) ˉ().getLayoutParams();
        layoutParams.height = -2;
        ˉ().setLayoutParams(layoutParams);
        this.ˋ.setMaxLine(hotWordCardBean.ㆍ());
        this.ˋ.ˏ = (int) ContentManager.getInstant().getContext().getResources().getDimension(a.ॱॱ);
        ˋ(this.ॱॱ == null ? this.ᐝ : this.ॱॱ);
    }

    protected void ˎ() {
        ˉ().setVisibility(8);
        LayoutParams layoutParams = (LayoutParams) ˉ().getLayoutParams();
        layoutParams.height = 0;
        ˉ().setLayoutParams(layoutParams);
    }

    public void ॱ(chy o_chy) {
        this.ˏॱ = o_chy;
    }

    protected void ˋ(List<HotWordInfo> list) {
        int i = 0;
        if (!CollectCheck.isEmpty((List) list)) {
            this.ˋ.removeAllViews();
            this.ˋ.setFirstRowTopMargin(0);
            if (ˌ() instanceof HotWordCardBean) {
                ((HotWordCardBean) ˌ()).ˎ(list);
            }
            while (i < list.size()) {
                View ॱ = ॱ((HotWordInfo) list.get(i));
                ॱ.setTag(Integer.valueOf(i));
                ॱ.setOnClickListener(new evx(this) {
                    final /* synthetic */ HotWordBaseCard ॱ;

                    {
                        this.ॱ = r1;
                    }

                    public void ˋ(View view) {
                        if (view != null && (this.ॱ.ˌ() instanceof HotWordCardBean)) {
                            HotWordCardBean hotWordCardBean = (HotWordCardBean) this.ॱ.ˌ();
                            hotWordCardBean.ʽ(((Integer) view.getTag()).intValue());
                            this.ॱ.ˏॱ.ˏ(7, this.ॱ);
                            dgh.onEvent(new d(ContentManager.getInstant().getContext(), f.ˋ).ˏ("02|" + hotWordCardBean.ʽ() + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + hotWordCardBean.ꜞ()).ˋ());
                            Context context = view.getContext();
                            if ((context instanceof Activity) && !TextUtils.isEmpty(hotWordCardBean.ʽ())) {
                                cvo.ॱ("250301", hotWordCardBean.ʽ(), hotWordCardBean.ॱ(), hotWordCardBean.ꓸ(), (Activity) context);
                                if (TextUtils.isEmpty(hotWordCardBean.ꜟ())) {
                                    cux.ˏ.ˋ("HotWordBaseCard", "The keyword detailId is empty.");
                                    return;
                                }
                                dyk.ॱ(context, hotWordCardBean.ॱˉ(), hotWordCardBean.ꜟ());
                                cfw.ˎ(dgu.ˋ("13", hotWordCardBean.ꜟ(), this.ॱ.ʻ), null);
                            }
                        }
                    }
                });
                this.ˋ.addView(ॱ);
                i++;
            }
        }
    }

    private View ॱ(HotWordInfo hotWordInfo) {
        View inflate = this.ʼ.inflate(e.ˋˊ, null);
        inflate.setLayoutParams(ˎ(inflate));
        ToggleButton toggleButton = (ToggleButton) inflate.findViewById(b.ˋʽ);
        toggleButton.setText(hotWordInfo.ˏ());
        toggleButton.setTextOn(hotWordInfo.ˏ());
        toggleButton.setTextOff(hotWordInfo.ˏ());
        toggleButton.setClickable(false);
        ˎ(hotWordInfo.ˎ(), toggleButton);
        return inflate;
    }

    private FrameLayout.LayoutParams ˎ(View view) {
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new FrameLayout.LayoutParams(-2, -2);
        }
        layoutParams.topMargin = (int) ContentManager.getInstant().getContext().getResources().getDimension(a.ᐝ);
        return layoutParams;
    }

    private LinkedHashMap<String, String> ˋ(String str, String str2) {
        LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("hotwordlist", str);
        linkedHashMap.put("labeltitle", str2);
        linkedHashMap.put("serviceType", String.valueOf(this.ʻ));
        return linkedHashMap;
    }

    public ArrayList<String> ˊ() {
        List list = this.ॱॱ == null ? this.ᐝ : this.ॱॱ;
        if (this.ˋ == null || CollectCheck.isEmpty(list) || this.ˋ.getChildCount() > list.size()) {
            return new ArrayList();
        }
        ArrayList<String> arrayList = new ArrayList();
        StringBuilder stringBuilder = new StringBuilder();
        if (this.ʽ == null) {
            this.ʽ = new HashMap();
        }
        int i = 0;
        while (i < this.ˋ.getChildCount()) {
            dyf o_dyf = new dyf();
            View childAt = this.ˋ.getChildAt(i);
            if (o_dyf.ˎ(childAt) && list.get(i) != null) {
                CharSequence ॱ = ((HotWordInfo) list.get(i)).ॱ();
                if (!TextUtils.isEmpty(ॱ)) {
                    arrayList.add(ॱ);
                }
                if (!this.ʽ.containsKey(childAt.getTag())) {
                    this.ʽ.put(childAt.getTag(), ((HotWordInfo) list.get(i)).ˏ());
                    stringBuilder.append("\"");
                    stringBuilder.append(((HotWordInfo) list.get(i)).ˏ());
                    stringBuilder.append("\"");
                    stringBuilder.append(",");
                }
            }
            i++;
        }
        if (stringBuilder.length() > 0) {
            dgh.ˋ("250302", ˋ(stringBuilder.toString().substring(0, stringBuilder.length() - 1), this.ˋॱ));
        }
        return arrayList;
    }

    protected void ˎ(int i, ToggleButton toggleButton) {
    }
}
